package com.workmanager.service;

import com.workmanager.bean.LeaveMessageBean;
import com.workmanager.mapper.LeaveMessageMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by haocongshun on 2016/9/14.
 */
@Service("leaveMessageService")
public class LeaveMessageService {
    @Resource(name="leaveMessageMapper")
    private LeaveMessageMapper leaveMessageMapper;

    public LeaveMessageMapper getLeaveMessageMapper() {
        return leaveMessageMapper;
    }

    public void setLeaveMessageMapper(LeaveMessageMapper leaveMessageMapper) {
        this.leaveMessageMapper = leaveMessageMapper;
    }
    public List<LeaveMessageBean> getMessage(String teacher_id,String student_id){
        Map<String,String> id = new HashMap<String, String>();
        id.put("teacher_id",teacher_id);
        id.put("student_id",student_id);
        return leaveMessageMapper.getMessage(id);
    }
    public List<LeaveMessageBean> getTea_to_Stu(String teacher_id){
        List<LeaveMessageBean> list =  leaveMessageMapper.getTea_to_Stu(teacher_id);
        Map<String,LeaveMessageBean> map = new HashMap<String, LeaveMessageBean>();
        List<LeaveMessageBean> relist = new ArrayList<LeaveMessageBean>();
        for(LeaveMessageBean lm1 : list){
            LeaveMessageBean l = map.get(lm1.getStudent_id());
            if(l==null){
                map.put(lm1.getStudent_id(),lm1);
                relist.add(lm1);
            }
        }
        return relist;
    }
    public List<LeaveMessageBean> getStu_to_Tea(String student_id){
        List<LeaveMessageBean> list =  leaveMessageMapper.getStu_to_Tea(student_id);
        Map<String,LeaveMessageBean> map = new HashMap<String, LeaveMessageBean>();
        List<LeaveMessageBean> relist = new ArrayList<LeaveMessageBean>();
        for(LeaveMessageBean lm1 : list){
            LeaveMessageBean l = map.get(lm1.getTeacher_id());
            if(l==null){
                map.put(lm1.getTeacher_id(),lm1);
                relist.add(lm1);
            }
        }
        return relist;
    }
    public boolean reLeaveMessage(LeaveMessageBean leaveMessage){
        leaveMessage.setLeaveMessage_id(leaveMessageMapper.getLeaveMessageId());
        return leaveMessageMapper.reLeaveMessage(leaveMessage);
    }
}
